home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / egets.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  73 lines

  1. /*
  2.  * Copyright 1987 Brian Beattie Rights Reserved.
  3.  *
  4.  * Permission to copy and/or distribute granted under the
  5.  * following conditions:
  6.  *
  7.  * 1). No charge may be made other than resonable charges
  8.  *    for reproduction.
  9.  *
  10.  * 2). This notice must remain intact.
  11.  *
  12.  * 3). No further restrictions may be added.
  13.  *
  14.  */
  15. #include <stdio.h>
  16. #include "tools.h"
  17. #include "ed.h"
  18.  
  19. int    truncflg = 1;    /* truncate long line flag */
  20. int    eightbit = 1;    /* save eight bit */
  21. int    nonascii, nullchar, truncated;
  22. egets(str,size,stream)
  23. char    *str;
  24. int    size;
  25. FILE    *stream;
  26. {
  27.     int    c, count;
  28.     char    *cp;
  29.  
  30.     for(count = 0, cp = str; size > count;)
  31.     {
  32.         c = getc(stream);
  33.         if(c == EOF)
  34.         {
  35.             *cp++ = '\n';
  36.             *cp = EOS;
  37.             if(count)
  38.             {
  39.                 printf("[Incomplete last line]\n");
  40.             }
  41.             return(count);
  42.         }
  43.         if(c == NL)
  44.         {
  45.             *cp++ = c;
  46.             *cp = EOS;
  47.             return(++count);
  48.         }
  49.         if(c > 127)
  50.         {
  51.             if(!eightbit)        /* if not saving eighth bit */
  52.                 c = c&127;    /* strip eigth bit */
  53.             nonascii++;        /* count it */
  54.         }
  55.         if(c)
  56.         {
  57.             *cp++ = c;    /* not null, keep it */
  58.             count++;
  59.         } else 
  60.             nullchar++;    /* count nulls */
  61.     }
  62.     str[count-1] = EOS;
  63.     if(c != NL)
  64.     {
  65.         printf("truncating line\n");
  66.         truncated++;
  67.         while((c = getc(stream)) != EOF)
  68.             if(c == NL)
  69.                 break;
  70.     }
  71.     return(count);
  72. }
  73.